<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    const arr = [1, 4, 3, 12, 8]
    const max = arr.reduce((pre, cur, index, list) => {
      return pre > cur ? pre : cur
    })
    console.log('max==', max)
    const sum = arr.reduce((pre, cur, index, list) => {
      return pre + cur
    }, 0)
    console.log('sum==', sum)

    const str = 'sfhjasfjgfasjuwqrqadqeiqsajsdaiwqdaklldflas-cmxzmnha'
    const strNum = str.split('').reduce((preObj, key) => {
      preObj[key] ? preObj[key]++ : (preObj[key] = 1)
      return preObj
    }, {})
    console.log('strNum==', strNum)

    // 扁平一个二维数组
    var arr2 = [
      [1, 2, 8],
      [3, 4, 9],
      [5, 6, 10],
    ]
    const newArr = arr2.reduce((pre, cur) => {
      return pre.concat(cur)
    }, [])
    console.log('newArr==', newArr)
  </script>
</html>
